import {Component, OnInit, OnDestroy} from '@angular/core';
import {SafeResourceUrl, DomSanitizer} from '@angular/platform-browser';
import {ApplicationService} from '../../service/application.service';
import {Subscription} from 'rxjs/Rx';

@Component({
  selector: 'app-report',
  templateUrl: './report.component.html',
  styleUrls: ['./report.component.css']
})
export class ReportComponent implements OnInit, OnDestroy {


  public href: SafeResourceUrl;
  public subject: Subscription;

  constructor(
    private application: ApplicationService,
    private sanitizer: DomSanitizer
  ) {

  }

  ngOnInit() {
    this.change();
    let subject = this.application.currentMenuParamsSubject.subscribe(
      next => {
        this.change();
      }
    )

  }

  ngOnDestroy(): void {
    if (this.subject) {
      this.subject.unsubscribe();
    }
  }

  change() {
    if (this.application.currentMenuParams && this.application.currentMenuParams['href']) {
      this.href = this.sanitizer.bypassSecurityTrustResourceUrl(this.application.appConfigData.appReport + '/' + this.application.currentMenuParams['href'].paramValue);
    }
    else {
      this.href = null;
    }
  }
}


// WEBPACK FOOTER //
// ./src/app/module/report/report.component.ts
